//
//  AppDelegate.m
//  Frame
//
//  Created by 这是工作本 on 15/12/25.
//  Copyright © 2015年 这是工作本. All rights reserved.
//

#import "AppDelegate.h"
#import "BMKMapManager.h"
#import "UMSocialWechatHandler.h"
#import "UMSocialQQHandler.h"

@interface AppDelegate ()<UITabBarControllerDelegate>

@property (nonatomic, retain) BMKMapManager *mapManager;

@property (nonatomic, retain) ZWIntroductionViewController *introductionView;

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    //即时通讯
    
    [[EaseMob sharedInstance] registerSDKWithAppKey:@"douser#istore" apnsCertName:@"istore_dev"];
    [[EaseMob sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
    
    
    
    //分享
    [UMSocialData setAppKey:@"569f009ce0f55a938f001d35"];
    [UMSocialData openLog:YES];
    
    //设置微信AppId，设置分享url，默认使用友盟的网址
    [UMSocialWechatHandler setWXAppId:@"wxd930ea5d5a258f4f" appSecret:@"db426a9829e4b49a0dcac7b4162da6b6" url:@"http://www.umeng.com/social"];
    
    //设置手机QQ的AppId，指定你的分享url，若传nil，将使用友盟的网址
    [UMSocialQQHandler setQQWithAppId:@"100424468" appKey:@"c7394704798a158208a74ab60104f0ba" url:@"http://www.umeng.com/social"];
    
    
    _mapManager = [[BMKMapManager alloc]init];
    // 如果要关注网络及授权验证事件，请设定     generalDelegate参数
    BOOL ret = [self.mapManager start:@"hrwjpTPANVKSNB1idX78mnYw" generalDelegate:nil];
    if (!ret) {
        NSLog(@"manager start failed!");
    }
    
   
    [self.window makeKeyAndVisible];
    
    // Add the navigation controller's view to the window and display.
    
    
  
    
    
    //首页
    HomePageViewController *home = [[HomePageViewController alloc] init];
    UINavigationController *homeNC = [[UINavigationController alloc] initWithRootViewController:home];


    homeNC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"主页" image:[[UIImage imageNamed:@"bais@2x.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"矩形-23@2x.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    
    // 场馆
    ActivityViewController *activity = [[ActivityViewController alloc] init];
    UINavigationController *activityNC = [[UINavigationController alloc] initWithRootViewController:activity];

        activityNC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"场馆" image:[[UIImage imageNamed:@"形状-19-.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"图层-60@2x.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    
    
    //约球
    ComPetitionViewController *comepetition = [[ComPetitionViewController alloc] init];
    UINavigationController *competitionNC = [[UINavigationController alloc] initWithRootViewController:comepetition];
    competitionNC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"约球" image:[[UIImage imageNamed:@"77.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"78.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    
    //我的
    
    PersonalViewController *person = [[PersonalViewController alloc] init];
    UINavigationController *personNC = [[UINavigationController alloc] initWithRootViewController:person];
    
    
    personNC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我的" image:[[UIImage imageNamed:@"椭圆-11-拷贝@2x.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"图层-61@2x.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    
    
    UITabBarController *tabBar = [[UITabBarController alloc] init];
    tabBar.delegate = self;
    tabBar.viewControllers = [NSArray arrayWithObjects:homeNC, activityNC,  competitionNC, personNC, nil];
    
    //tablebar颜色
    tabBar.tabBar.barTintColor = [UIColor colorWithRed:255 / 255.0 green:255 / 255.0  blue:255 / 255.0  alpha:1.0];
    
    //选中颜色
    for (UIBarItem *item in tabBar.tabBar.items) {
        [item setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                      [UIFont fontWithName:@"Helvetica" size:10.0], NSFontAttributeName, [UIColor lightGrayColor], NSForegroundColorAttributeName,nil]
                            forState:UIControlStateNormal];
        [item setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                      [UIFont fontWithName:@"Helvetica" size:10.0], NSFontAttributeName, [UIColor colorWithRed:29 / 255.0 green:127 / 255.0  blue:140 / 255.0  alpha:1.0], NSForegroundColorAttributeName,nil]
                            forState:UIControlStateSelected];
        
    }
    
    
//    tabBar.tabBar.tintColor = [UIColor colorWithRed:249 / 255.0 green:182 / 255.0 blue:21 / 255.0 alpha:1.0];
    
    self.window.rootViewController = tabBar;
    
    
    //引导页
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    BOOL lead = [user boolForKey:@"yindao"];
    
    if (NO == lead) {
        NSArray *coverImageNames = @[@"sheshou", @"", @""];
        NSArray *backgroundImageNames = @[@"QQ图片20150713225950.jpg", @"QQ图片20150718130427.jpg", @"QQ图片20150718130526.jpg"];
        UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(self.window.frame.size.width / 2 - 80 * ScreenWidth, self.window.frame.size.height - 80 * ScreenHeigth, 80 * 2 * ScreenWidth, 40 * ScreenHeigth)];
        [button setTitle:@"开始体验" forState:UIControlStateNormal];
        //button.font = [UIFont boldSystemFontOfSize:20.0];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [button.layer setCornerRadius:14.0 * ScreenWidth];
        [button.layer setBorderWidth:2.0 * ScreenWidth];
        [button.layer setBorderColor:[[UIColor whiteColor] CGColor]];
        self.introductionView = [[ZWIntroductionViewController alloc] initWithCoverImageNames:coverImageNames backgroundImageNames:backgroundImageNames button:button];
        //self.introductionView = [[ZWIntroductionViewController alloc] initWithCoverImageNames:coverImageNames backgroundImageNames:backgroundImageNames];
        
        [self.window addSubview:self.introductionView.view];
        
        self.introductionView.didSelectedEnter = ^() {
            [self.introductionView.view removeFromSuperview];
            self.introductionView = nil;
            
            NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
            [user setBool:YES forKey:@"yindao"];
            
            
        };
    }
    
    
    return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    //APP进入后台
    
      [[EaseMob sharedInstance] applicationDidEnterBackground:application];
    
    
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
    //APP将要从后台返回
    
    [[EaseMob sharedInstance] applicationWillEnterForeground:application];
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    
    //申请处理时间
    
    [[EaseMob sharedInstance] applicationWillTerminate:application];
}

@end
